import time

from selenium import webdriver

class   BasePage1:
    def __init__(self,driver= None):
        if driver is not None:
            self.driver = driver
        else:
            self.driver = webdriver.Chrome
            self.driver.maximize_window()
            self.driver.implicitly_wait(10)

    #封装行为:输入文本框  输入文本
    def input(self,target,value):
        self.element_locate(target).send_keys(value)

    def element_locate(self, target): #定位方法,定位语句
        method,value = self.convert(target)
        return self.driver.find_element(method,value)  #method定位方法 value为定位元素的值

    def convert(self, target):
        method , value =  target.split(',')
        return method.strip(),value.strip()

    def click(self,target):  #点击方法
        self.element_locate(target).click()

    def get_ele_text(self,target): #返回获取到的文本
        return self.element_locate(target).text

    def into_frame(self,frame_name):
        self.driver.switch_to.frame(frame_name)

    def wait(self,num):
        time.sleep(num)

    def open(self,url):
        self.driver.get(url)

    def quit(self):
        self.driver.quit()


if __name__ == '__main__':
    bg = BasePage1
    bg.open("https://www.csdn.net/?spm=1000.2115.3001.4476")
    bg.wait(2)
